home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / DTSCPlusLibrary / Sources / AppleEvent.cp next >
Encoding:
Text File  |  1993-01-14  |  4.3 KB  |  170 lines  |  [TEXT/MPS ]

  1. /* _________________________________________________________________________________________________________ //
  2.   Copyright © 1992 Apple Computer, Inc. All rights reserved.
  3.   Macintosh Developer Technical Support.C++ Macintosh Toolbox Framework.
  4.   Date: 11/22/92
  5.   Programmer: Kent Sandvik
  6.   Revision comments are at the end of this file.
  7.   ---
  8.   TAppleEvent is an Apple Event class that will send and receive Apple Events.
  9.   AppleEvent.cp contains the member functions for the TAppleEvent class.
  10.   _________________________________________________________________________________________________________ */
  11.  
  12.  
  13. // INCLUDE FILES
  14. #ifndef _APPLEEVENT_
  15. #include "AppleEvent.h"
  16. #endif
  17.  
  18. //    GLOBALS
  19. const ProcessSerialNumber kSelf = {
  20.                                    0, kCurrentProcess};
  21.  
  22.  
  23. // _________________________________________________________________________________________________________ //
  24. // TAppleEvent class member function implementations
  25. //    CONSTRUCTORS & DESTRUCTORS
  26. #pragma segment AppleEvent
  27. TAppleEvent::TAppleEvent()
  28. // Create a kCurrentProcess address Apple Event.
  29. {
  30.     this->Initialize();
  31.     fError = ::AECreateDesc(typeProcessSerialNumber, (Ptr) & kSelf, sizeof(ProcessSerialNumber), &fTarget);
  32.     VASSERT(fError == noErr, ("Problems with AECreateDesc = %d", fError));
  33. }
  34.  
  35.  
  36. #pragma segment AppleEvent
  37. TAppleEvent::TAppleEvent(OSType signature)
  38. // Create an AE based on the signature type.
  39. {
  40.     this->Initialize();
  41.     fSignature = signature;
  42.  
  43.     // Create an AEDescriptor from the signature.
  44.     fError = ::AECreateDesc(typeApplSignature, (Ptr) & fSignature, sizeof(fSignature), &fTarget);
  45.     VASSERT(fError == noErr, ("Problems with AECreateDesc = %d", fError));
  46. }
  47.  
  48.  
  49. #pragma segment AppleEvent
  50. TAppleEvent::~TAppleEvent()
  51. {
  52.     ::AEDisposeDesc(&fAE);                        // dispose our AE handle
  53. }
  54.  
  55.  
  56. #pragma segment AppleEvent
  57. void TAppleEvent::Initialize()
  58. // Initialize fields to known values.
  59. {
  60.     fPriority = kAENormalPriority;                // normal level of priority
  61.     fTimeout = kNoTimeOut;                        // no waiting, just continue
  62.     fSendMode = kAENoReply;                        // default we are not expecting replies
  63.     fAE.dataHandle = NULL;                        // clear the message part
  64. }
  65.  
  66.  
  67. //    MAIN INTERFACES
  68. #pragma segment AppleEvent
  69. OSErr TAppleEvent::Define(AEEventClass theClass,
  70.                           AEEventID ID)
  71. // Define the AE based on the AE class and ID.
  72. {
  73.     fError = ::AECreateAppleEvent(theClass, ID, &fTarget, kAutoGenerateReturnID, kAnyTransactionID, &fAE);
  74.     VASSERT(fError == noErr, ("Problems with AECreateAppleEvent = %d", fError));
  75.  
  76.     return fError;
  77. }
  78.  
  79.  
  80. #pragma segment AppleEvent
  81. OSErr TAppleEvent::Send()
  82. // Blast off the Apple Event.
  83. {
  84.     fError = ::AESend(&fAE, &fReply, fSendMode, fPriority, fTimeout, nil, nil);
  85.     VASSERT(fError == noErr, ("Problems with AESend = %d", fError));
  86.  
  87.     return fError;
  88. }
  89.  
  90.  
  91. #pragma segment AppleEvent
  92. OSErr TAppleEvent::Send(AEEventClass theClass,
  93.                         AEEventID ID)
  94. // Blast off the AE with the specs
  95. {
  96.     this->Define(theClass, ID);                    // define the AE
  97.     fError = ::AESend(&fAE, &fReply, fSendMode, fPriority, fTimeout, nil, nil);
  98.     VASSERT(fError == noErr, ("Problems with AESend = %d", fError));
  99.  
  100.     return fError;
  101. }
  102.  
  103.  
  104. #pragma segment AppleEvent
  105. void TAppleEvent::SetAddress(const AEAddressDesc address)
  106. // Set the address of the target AE.
  107. {
  108.     fError = ::AEPutAttributeDesc(&fAE, keyAddressAttr, &address);
  109.     VASSERT(fError == noErr, ("Problems with AEPutAttributeDesc = %d", fError));
  110. }
  111.  
  112.  
  113. //    GET/SET MEMBER FUNCTIONS
  114. #pragma segment AppleEvent
  115. long TAppleEvent::GetTimeoutValue() const
  116. // Get current timeout value.
  117. {
  118.     return fTimeout;
  119. }
  120.  
  121.  
  122. #pragma segment AppleEvent
  123. void TAppleEvent::SetTimeoutValue(const long value)
  124. // Set new timeout value.
  125. {
  126.     fTimeout = value;
  127. }
  128.  
  129.  
  130. #pragma segment AppleEvent
  131. AESendMode TAppleEvent::GetSendingMode() const
  132. // Get AE sending mode.
  133. {
  134.     return fSendMode;
  135. }
  136.  
  137.  
  138. #pragma segment AppleEvent
  139. void TAppleEvent::SetSendingMode(const AESendMode mode)
  140. // Set new AE sending mode.
  141. {
  142.     fSendMode = mode;
  143. }
  144.  
  145.  
  146. #pragma segment AppleEvent
  147. AESendPriority TAppleEvent::GetPriority() const
  148. // Get current priority level.
  149. {
  150.     return fPriority;
  151. }
  152.  
  153.  
  154. #pragma segment AppleEvent
  155. void TAppleEvent::SetPriority(const AESendPriority value)
  156. // Set new priority level.
  157. {
  158.     fPriority = value;
  159. }
  160.  
  161.  
  162. // _________________________________________________________________________________________________________ //
  163.  
  164. /*    Change History (most recent last):
  165.   No        Init.    Date        Comment
  166.   1            khs        11/22/92    New file
  167.   2            khs        1/7/93        Cleanup
  168. */
  169.  
  170.